---
id: 65577791ad8c26a7705e2919
title: ステップ 29
challengeType: 20
dashedName: step-29
---

# --description--

With a dictionary comprehension, you can create a dictionary starting from an existing dictionary:

```py
{key: val for key in dict}
```

You want to keep track of the paths between the starting node and each other node.

After the `distances` variable, create a `paths` variable and assign it a dictionary with all the keys from `graph`. Assign an empty list to each key and use a dictionary comprehension to build your dictionary.

# --hints--

You should have a `paths` variable.

```js
({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^\s{4}paths\s*\=/m));
  }
})
```

Your `paths` variable should use the dictionary comprehension syntax to assign an empty list to each node in graph.

```js
({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^\s{4}paths\s*\=\s*\{\s*(\w+)\s*:\s*\[\s*\]\s+for\s+\1\s+in\s+graph\s*\}/m));
  }
})
```

# --seed--

## --seed-contents--

```py
my_graph = {
    'A': [('B', 3), ('D', 1)],
    'B': [('A', 3), ('C', 4)],
    'C': [('B', 4), ('D', 7)],
    'D': [('A', 1), ('C', 7)]
}

--fcc-editable-region--
def shortest_path(graph, start):
    unvisited = list(graph)
    distances = {}

    print(f'Unvisited: {unvisited}\nDistances: {distances}')

shortest_path(my_graph, 'A')
--fcc-editable-region--
```
